<?php
require_once('TVB/pms/pdes/common/util/CommonUtils.class.php');
require_once('TVB/pms/pdes/common/util/XmlToArray.class.php');
require_once('TVB/pms/pdes/common/AppConfiguration.class.php');

$url_parameter = CommonUtils::make_url_parameter($_REQUEST, AC::$mam_filter);
$mam_config = array(
	'01' => sprintf('getProgrammeCount.xml'),
	'02' => sprintf('getAllProgramme.xml'),
	'03' => sprintf('getProgrammeDetails.xml'),
	'04' => sprintf('getEpisodeNoByProgramme.xml'),
	'05' => sprintf('getEpisodeAndItemDetails.xml'),
	'06' => sprintf('getMusicThemebyProgramme.xml'),
	'07' => sprintf('getRestrictionbyProgramme.xml'),
	'08' => sprintf('getRestrictionbyEpisode.xml'),
	'09' => sprintf('getRestrictionByItem.xml'),
	'10' => sprintf('getCastingbyProgramme.xml'),
	'11' => sprintf('getCastingbyEpisode.xml'),
	'12' => sprintf('getCastingbyItem.xml')
);

$xml = new xml();
if ($_REQUEST['type'] == "programme")
{
	$func_code = array(3,4,6,7,10);
	foreach ($func_code as $code)
	{
		$url = AC::MAM_API_URL.$url_parameter."&FUNCT_CODE=".$code;
		$ret = CommonUtils::curl_test($url);
		$out = $xml->parse($ret, NULL);
		var_export($out);
	}
}
//call function

$json_data = array(
	"autofill"=>array(
		array("programme_name"=>trim($out['Programmes']['Programme']['CHINESE_TITLE']),

	),
	array(
		"number_of_episodes"=>$out['Programmes']['Programme']['NUM_OF_EPI']
	)
),	
	"manualfill"=>array(
		array(
		"cast"=> array(
			array(
			"role"=>'222',
			"name"=>'333',
		),
			array(
			"role"=>'222',
			"name"=>'333',
		),
			array(
			"role"=>'222',
			"name"=>'333',
		),
			array(
			"role"=>'222',
			"name"=>'333',
		)
	)),
	array('restriction'=>array(
		array('name'=>'aaa',
		'id'=>'sss'
		),
		array('name'=>'bbb',
		'id'=>'bbb'
		)
	)),
	array(
	"descrption"=>"今日比賽的兩個隊伍分別是聖公會阮鄭夢芹小學(下午校"
)
	)

	);
echo json_encode($json_data);
?>

